package com.xzc.refactory.method.splitTemporaryVariable;

public class C8 {
    double _primaryForce;
    double _secondaryForce;
    double _mass;
    int _delay;

    double getDistanceTravelled(int time) {
        double result;
        //first acc
        result = 0.5 * primaryAcc() * primaryTime(time) * primaryTime(time);
        if (secondaryTime(time) > 0) {
            //sec acc
            result += primaryVel() * secondaryTime(time) + 0.5 * secondaryAcc() * secondaryTime(time) * secondaryTime(time);
        }
        return result;
    }

    double primaryAcc() {
        return _primaryForce / _mass;
    }

    int primaryTime(int time) {
        return Math.min(time, _delay);
    }

    int secondaryTime(int time) {
        return time - _delay;
    }

    double primaryVel() {
        return primaryAcc() * _delay;
    }

    double secondaryAcc() {
        return (_primaryForce + _secondaryForce) / _mass;
    }
}
